﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    mc:Ignorable="d">
	<!-- Resource dictionary entries should be defined here. -->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Colors.xaml"/>
        <ResourceDictionary Source="ScrollViewerStyle.xaml"/>
        <ResourceDictionary Source="ComboBoxItemStyle.xaml"/>
        <ResourceDictionary Source="ValidationToolTipTemplate.xaml"/>
        <ResourceDictionary Source="CheckBoxStyle.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type ComboBox}">
        <Setter Property="Foreground">
            <Setter.Value>
                <SolidColorBrush Color="{StaticResource Application_Control_Foreground}"/>
            </Setter.Value>
        </Setter>
        <Setter Property="SnapsToDevicePixels" Value="true" />
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.CanContentScroll" Value="true" />
        <Setter Property="MinWidth" Value="120" />
        <Setter Property="MinHeight" Value="20" />
        <Setter Property="Width" Value="120" />
        <Setter Property="Height" Value="20" />
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=ComboBoxTemplate, TypeInTargetAssembly={x:Type ComboBox}}}"/>
        <Setter Property="ItemContainerStyle" Value="{DynamicResource ComboBoxItemStyle}"/>
    </Style>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=ComboBoxTemplate, TypeInTargetAssembly={x:Type ComboBox}}" TargetType="{x:Type ComboBox}">
		<Grid>
    		<VisualStateManager.VisualStateGroups>
    			<VisualStateGroup x:Name="FocusStates">
    				<VisualState x:Name="Unfocused"/>
    				<VisualState x:Name="Focused">
    					<Storyboard AutoReverse="True" RepeatBehavior="Forever">
    						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="FocusVisualElement">
    							<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    							<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.5"/>
    						</DoubleAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="FocusedDropDown">
    					<Storyboard>
    						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="FocusVisualElement">
    							<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    						</DoubleAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="CommonStates">
    				<VisualStateGroup.Transitions>
    					<VisualTransition From="MouseOver" GeneratedDuration="0:0:0.3" To="Normal"/>
    					<VisualTransition From="Normal" GeneratedDuration="0:0:0.3" To="MouseOver"/>
    				</VisualStateGroup.Transitions>
    				<VisualState x:Name="Normal"/>
    				<VisualState x:Name="MouseOver"/>
    				<VisualState x:Name="Disabled">
    					<Storyboard>
    						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
    							<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ComboBox_Foreground_Disabled}"/>
    						</ColorAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="ValidationStates">
    				<VisualState x:Name="Valid">
    					<Storyboard>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
    						</ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="InvalidFocused">
    					<Storyboard>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    						</ObjectAnimationUsingKeyFrames>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToolTip.IsOpen)" Storyboard.TargetName="validationTooltip">
    							<DiscreteObjectKeyFrame KeyTime="0">
    								<DiscreteObjectKeyFrame.Value>
    									<sys:Boolean>true</sys:Boolean>
    								</DiscreteObjectKeyFrame.Value>
    							</DiscreteObjectKeyFrame>
    						</ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="InvalidUnfocused">
    					<Storyboard>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    						</ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="EditStates">
    				<VisualState x:Name="Editable">
    					<Storyboard>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PART_EditableTextBox">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    						</ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="Uneditable"/>
    			</VisualStateGroup>
    		</VisualStateManager.VisualStateGroups>
    		<ToggleButton x:Name="ToggleButton" Template="{DynamicResource {ComponentResourceKey ResourceId=ComboBoxToggleButtonTemplate, TypeInTargetAssembly={x:Type ToggleButton}}}"
    			Grid.Column="2" Focusable="false" ClickMode="Press" 
    			IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
    		<ContentPresenter x:Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}"
    			ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
    			Margin="5,3,25,3" VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
    		<TextBox x:Name="PART_EditableTextBox" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="5,3,25,3"
    			Focusable="True" Background="Transparent" Visibility="Hidden" IsReadOnly="{TemplateBinding IsReadOnly}" IsHitTestVisible="False">
    			<TextBox.Foreground>
    				<SolidColorBrush Color="{StaticResource Application_ComboBox_Foreground}"/>
    			</TextBox.Foreground>
    			<TextBox.Template>
    				<ControlTemplate TargetType="{x:Type TextBox}">
    					<Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
    				</ControlTemplate>
    			</TextBox.Template>
    		</TextBox>
    		<Popup x:Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True"
    			Focusable="False" PopupAnimation="Slide">
    			<Grid x:Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
    				<Border x:Name="DropDownBorder"
    					BorderThickness="1">
    					<Border.BorderBrush>
    						<SolidColorBrush Color="{StaticResource Application_ComboBoxDropDown_BorderBrush}" />
    					</Border.BorderBrush>
    					<Border.Background>
    						<SolidColorBrush Color="{StaticResource Application_ComboBoxDropDown_Background}" />
    					</Border.Background>
    				</Border>
    				<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
    					<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
    				</ScrollViewer>
    			</Grid>
    		</Popup>
    		<Border x:Name="FocusVisualElement" BorderThickness="1" Margin="0" CornerRadius="2" Visibility="Visible" IsHitTestVisible="False" Opacity="0">
    			<Border.BorderBrush>
    				<SolidColorBrush Color="{StaticResource Application_ComboBox_BorderBrush_Focus}"/>
    			</Border.BorderBrush>
    		</Border>
    		<Border x:Name="ValidationErrorElement" BorderThickness="1" Margin="0" CornerRadius="2" Visibility="Collapsed" IsHitTestVisible="True">
    			<Border.BorderBrush>
    				<SolidColorBrush Color="{StaticResource Application_ComboBox_BorderBrush_ValidationError}"/>
    			</Border.BorderBrush>
    			<ToolTipService.ToolTip>
    				<ToolTip x:Name="validationTooltip" Placement="Bottom"
    					Template="{DynamicResource ValidationToolTipTemplate}"
    					PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
    					DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"/>
    			</ToolTipService.ToolTip>
    		</Border>
    	</Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="HasItems" Value="false">
                <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95" />
            </Trigger>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false" />
            </Trigger>
            <Trigger SourceName="Popup" Property="AllowsTransparency" Value="true">
                <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

	<ControlTemplate x:Key="{ComponentResourceKey ResourceId=ComboBoxToggleButtonTemplate, TypeInTargetAssembly={x:Type ToggleButton}}" TargetType="{x:Type ToggleButton}">
        <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
			<Grid.ColumnDefinitions>
				<ColumnDefinition />
				<ColumnDefinition Width="20" />
			</Grid.ColumnDefinitions>
			<VisualStateManager.VisualStateGroups>
				<VisualStateGroup x:Name="CommonStates">
					<VisualStateGroup.Transitions>
						<VisualTransition From="Normal" GeneratedDuration="0:0:0.4" To="MouseOver"/>
						<VisualTransition From="MouseOver" GeneratedDuration="0:0:0.4" To="Normal"/>
					</VisualStateGroup.Transitions>
					<VisualState x:Name="Normal"/>
					<VisualState x:Name="MouseOver">
						<Storyboard>
							<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Border">
								<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ComboBox_Background_Move}"/>
							</ColorAnimationUsingKeyFrames>
							<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="Arrow">
								<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ComboBoxButton_Foreground_Move}"/>
							</ColorAnimationUsingKeyFrames>
						</Storyboard>
					</VisualState>
					<VisualState x:Name="Pressed">
						<Storyboard>
							<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Border">
								<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ComboBox_Background_Move}"/>
							</ColorAnimationUsingKeyFrames>
							<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="Arrow">
								<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ComboBoxButton_Foreground_Move}"/>
							</ColorAnimationUsingKeyFrames>
						</Storyboard>
					</VisualState>
					<VisualState x:Name="Disabled">
						<Storyboard>
							<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
								<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ComboBox_Foreground_Disabled}"/>
							</ColorAnimationUsingKeyFrames>
							<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="Arrow">
								<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ComboBoxButton_Foreground_Disabled}"/>
							</ColorAnimationUsingKeyFrames>
						</Storyboard>
					</VisualState>
				</VisualStateGroup>
				<VisualStateGroup x:Name="CheckStates">
					<VisualState x:Name="Checked">
						<Storyboard>
							<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="CheckedBorder">
								<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
							</DoubleAnimationUsingKeyFrames>
						</Storyboard>
					</VisualState>
					<VisualState x:Name="Unchecked"/>
					<VisualState x:Name="Indeterminate"/>
				</VisualStateGroup>
			</VisualStateManager.VisualStateGroups>
			<Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="2" BorderThickness="1">
				<Border.BorderBrush>
					<SolidColorBrush Color="{StaticResource Application_ComboBox_BorderBrush}"/>
				</Border.BorderBrush>
				<Border.Background>
					<SolidColorBrush Color="{StaticResource Application_ComboBox_Background}"/>
				</Border.Background>
			</Border>
			<Border x:Name="CheckedBorder" Grid.ColumnSpan="2" CornerRadius="2" BorderThickness="1" Opacity="0">
				<Border.BorderBrush>
					<SolidColorBrush Color="{StaticResource Application_ComboBox_BorderBrush}"/>
				</Border.BorderBrush>
				<Border.Background>
					<SolidColorBrush Color="{StaticResource Application_ComboBox_Background_Move}"/>
				</Border.Background>
			</Border>
			<Path x:Name="Arrow" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M0,0L4,4 8,0" Fill="{x:Null}" >
				<Path.Stroke>
					<SolidColorBrush Color="{StaticResource Application_ComboBoxButton_Foreground}"/>
				</Path.Stroke>
			</Path>
		</Grid>
    </ControlTemplate>

</ResourceDictionary>